package eashrine;

import org.junit.jupiter.api.Test;

import java.util.Arrays;

/**
 * @Author: Siantar
 * @Date: 2023-11-10-22:33
 * @Description: 1.0
 */
public class T2300 {
    class Solution {
        public int[] successfulPairs(int[] spells, int[] potions, long success) {
            Arrays.sort(potions);
            int n = spells.length, m = potions.length;
            int[] res = new int[n];
            for (int i = 0; i < n; i++) {
                long t = (success + spells[i] - 1) / spells[i] - 1;
                res[i] = m - binarySearch(potions, 0, m - 1, t);
            }
            return res;
        }

        public int binarySearch(int[] arr, int lo, int hi, long target) {
            int res = hi + 1;
            while (lo <= hi) {
                int mid = lo + (hi - lo) / 2;
                if (arr[mid] > target) {
                    res = mid;
                    hi = mid - 1;
                } else {
                    lo = mid + 1;
                }
            }
            return res;
        }
    }
    @Test
    public void test() {
        System.out.println(Arrays.binarySearch(new int[]{4,5,6,7},5));
    }
}
